package com.edroid.autorunner.um;

import java.lang.reflect.Field;
import java.util.Random;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.SystemProperties;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;

import com.edroid.apkhooker.db.ImeiDB;
import com.edroid.apkhooker.db.ModelDB;
import com.edroid.apkhooker.db.ModelDB.Model;
import com.edroid.autorunner.AutoRunActivity;
import com.example.utils.Logger;

public class UserMaker {
	static final String TAG = "UserMaker";
	static final Logger log = Logger.create(TAG);
	public static int currentImeiIndex;
	private static Random random = new Random();
	private static int defOP = 0;
	private static final UserInfo oriUserInfo = new UserInfo();
//	public static String oriImsi = "460022937853866",
//		oriImei = "356278057396055", 
//		oriSim = "89360219836211765606",
//		oriMac = "00-00-00-00-00-00";
	public static final char[] hexs = "0123456789abcdef".toCharArray();
	public static final char[] hexs2 = "0123456789ABCDEF".toCharArray();
	
	
	private static final String[] SSIDS = {
		"@Wanda","KFC", "猎豹免费wifi","盛世158","FAST","搜到爹了吧","小度wifi"
		,"aWIFI","HIWIFI_2A32F3","SRWS-FREE","百米宏创","YunWIFIFree","免费wifi"
		,"DreamBox","PandoraBox","OpenWrt","asus","free","CMCC-4G","CMCC-FREE"
		,"hehe"
	};
	
	static final int[] NETWORK_TYPE_2G = { //60%
    	TelephonyManager.NETWORK_TYPE_GPRS,
    	TelephonyManager.NETWORK_TYPE_EDGE,
		TelephonyManager.NETWORK_TYPE_CDMA,
		TelephonyManager.NETWORK_TYPE_1xRTT,
		TelephonyManager.NETWORK_TYPE_IDEN
    };
    
    static final int[] NETWORK_TYPE_3G = { //38%
	    TelephonyManager.NETWORK_TYPE_UMTS,
	    TelephonyManager.NETWORK_TYPE_EVDO_0,
	    TelephonyManager.NETWORK_TYPE_EVDO_A,
	    TelephonyManager.NETWORK_TYPE_HSDPA,
	    TelephonyManager.NETWORK_TYPE_HSUPA,
	    TelephonyManager.NETWORK_TYPE_HSPA,
	    TelephonyManager.NETWORK_TYPE_EVDO_B,
	    TelephonyManager.NETWORK_TYPE_EHRPD,
    	TelephonyManager.NETWORK_TYPE_HSPAP
    };
    
    static final int[] NETWORK_TYPE_4G = { //2
    	TelephonyManager.NETWORK_TYPE_LTE
    };
    
    static final int[] PHONE_TYPE = { //2
    	TelephonyManager.PHONE_TYPE_CDMA,
    	TelephonyManager.PHONE_TYPE_GSM,
    	TelephonyManager.PHONE_TYPE_SIP,
    	TelephonyManager.PHONE_TYPE_NONE
    };
    
    static final String[] APNS_2G = {"cmnet", "ctnet", "uninet"};
    static final String[] APNS_3G = {"cmnet", "3gnet"};
    static final String[] APNS_4G = {"4glte"};
	
    static final String[] ISO = {"ao", "al", "af", "dz", "bs", "bh", "bd", "bb", "mm", "cm", "cf", "ca", "dk", "eg", "fi",
    	"de", "hk", "it"};
    
    final static int[][] nums = {
		{134, 135, 136, 137, 138, 139, 150, 151, 158, 159, 187, 188},
		{130, 131, 132, 152, 155, 156, 185, 186 },
		{133, 153, 180, 189}
    };
    final static int[][] scns = {
    	{600,752,220},{480,782,200},{1080,1800,460},{240,320,120},{768,976,250},{540,888,240},{720,1184,320},{600,976,240},{640,960,240},{800,600,240},
    	{1080,1776,320},{600,1024,200},{600,1018,350},{720,1232,330},{800,1280,320},{480,764,320},{480,752,220},{720,1208,300},{480,728,200}
    };
    
    //运营商类型
    public static final int OP_ALL = 0, OP_YD = 1, OP_LT = 2, OP_DX = 3;
    

	public static void setDefOP(int defOP) {
		UserMaker.defOP = defOP;
	}
	
	
	private static void makeOthersRandom(UserInfo userInfo) {
		makeScreenSize(userInfo);

		userInfo.aid = makeAid();
		userInfo.sid = makeSid();

		//版本 2014/09/18 统计数据 <img src="http://himg2.huanqiu.com/attachment2010/2014/0918/20140918113520126.jpg">
		{
			double f = random.nextDouble();
			if(f < 0.0711) {//8 2.2
				final String[] ss = {"2.2.2"};
				userInfo.sdk_int = 8;
				userInfo.sdk = ss[random.nextInt(ss.length)];
			} else if (f < 0.1853) {//10 2.3.3~2.3.7
				final String[] ss = {"2.3.3", "2.3.4", "2.3.5", "2.3.6", "2.3.7"};
				userInfo.sdk_int = 10;
				userInfo.sdk = ss[random.nextInt(ss.length)];
			} else if (f < 0.2818) {//15 9.6% 4.0.1~4.0.4
				final String[] ss = {"4.0.1", "4.0.4", "4.0.3", "4.0.2"};
				userInfo.sdk_int = 15;
				userInfo.sdk = ss[random.nextInt(ss.length)];
			} else if (f < 0.5329) {//16 4.1.x
				final String[] ss = {"4.1", "4.1.1", "4.1.2"};
				userInfo.sdk_int = 16;
				userInfo.sdk = ss[random.nextInt(ss.length)];
			} else if (f < 0.7346) {//17 4.2.x
				final String[] ss = {"4.2", "4.2.2", "4.2.1"};
				userInfo.sdk_int = 17;
				userInfo.sdk = ss[random.nextInt(ss.length)];
			} else if (f < 0.8169) {//18 4.3
				final String[] ss = {"4.3", "4.3.0", "4.3.1", "4.3.2", "4.3.3"};
				userInfo.sdk_int = 18;
				userInfo.sdk = ss[random.nextInt(ss.length)];
			} else if (f < 0.9900) {//19 4.4
				final String[] ss = {"4.4", "4.4.1", "4.4.2", "4.4.3", "4.4.4"};
				userInfo.sdk_int = 19;//Build.VERSION.SDK_INT;
				userInfo.sdk = ss[random.nextInt(ss.length)];
			} else {//others 
				final String[] ss = {"L", "4.5", "4.6", "ios 7.0", "ios 8.0", "4.4.5",
						"5.0", "6.0", "9.9.9", "unknow", "3.0", "3.1", "3.2",
						"xxx", "x.x.x", "1.5", "1.6", "1.0"};
				userInfo.sdk_int = 21;//Build.VERSION.SDK_INT;
				userInfo.sdk = ss[random.nextInt(ss.length)];
			}
		}
		
		/*{
			userInfo.model = TYPES[r.nextInt(TYPES.length)];
			String[] ss = userInfo.model.split(" ");
			if(ss != null && ss.length > 0)
				userInfo.manufacturer = ss[0];
			else
				userInfo.manufacturer = userInfo.model;
			userInfo.brand = userInfo.manufacturer;
			
			userInfo.hardware = HARDWARES[r.nextInt(HARDWARES.length)];
			userInfo.device = userInfo.hardware;
			userInfo.board = userInfo.hardware;
		}*/
		Model model = ModelDB.getModelDB().getModelById(random.nextInt(ModelDB.getModelDB().getModelTotal()));
//		Log.e("UserMaker",model.toString());
		
		userInfo.model = model.model;
		userInfo.manufacturer = model.manufacturer;
		userInfo.brand = model.brand;
		userInfo.hardware = model.hardware;
		userInfo.device = model.hardware;
		userInfo.board = model.board;
		userInfo.baseband = model.baseband;
		//TODO
		userInfo.fingerprint = userInfo.brand + "/" + userInfo.board + "/" + userInfo.board+":"+userInfo.sdk
				+ "/" + Build.ID + "/" + Build.TIME + ":" + Build.TYPE + "/" + Build.TAGS;
/*	    private static String deriveFingerprint() {
	        String finger = SystemProperties.get("ro.build.fingerprint");
	        if (TextUtils.isEmpty(finger)) {
	            finger = getString("ro.product.brand") + '/' +
	                    getString("ro.product.name") + '/' +
	                    getString("ro.product.device") + ':' +
	                    getString("ro.build.version.release") + '/' +
	                    getString("ro.build.id") + '/' +
	                    getString("ro.build.version.incremental") + ':' +
	                    getString("ro.build.type") + '/' +
	                    getString("ro.build.tags");
	        }
	        return finger;
	    }
*/
	}
	
	/**
	 * 生成分辨率
	 * 
	 * 低密度，DENSITY_LOW，120，
	 * 中密度，DENSITY_MEDIUM，160，
	 * 高密度，DENSITY_HIGH，240，
	 * 超高密度，DENSITY_XHIGH，320，
	 * 默认密度，DENSITY_DEFAULT，160（即中密度）。
	 * 
	 * @param userInfo
	 */
	private static void makeScreenSize(UserInfo userInfo) {
		{
			double f = random.nextDouble();
			if (f < 0.2705) {
				userInfo.screenWidth = 480;
				userInfo.screenHeight = 800;
				userInfo.densityDpi = 240;
			} else if (f < 0.5369) {
				userInfo.screenWidth = 480;
				userInfo.screenHeight = 854;
				userInfo.densityDpi = 240;
			} else if (f < 0.6833) {
				userInfo.screenWidth = 720;
				userInfo.screenHeight = 1280;
				userInfo.densityDpi = 320;
			} else if (f < 0.8010) {
				userInfo.screenWidth = 540;
				userInfo.screenHeight = 960;
				userInfo.densityDpi = 320;
			} else if (f < 0.9102) {
				userInfo.screenWidth = 1080;
				userInfo.screenHeight = 1920;
				userInfo.densityDpi = 480;
			} else if (f < 0.9500) {
				userInfo.screenWidth = 320;
				userInfo.screenHeight = 480;
				userInfo.densityDpi = 160;
			} else {
				int x = random.nextInt(scns.length);
				userInfo.screenWidth = scns[x][0];
				userInfo.screenHeight = scns[x][1];
				userInfo.densityDpi = scns[x][2];
			}
		}
	}
	/**
	 * 生成手机信息
	 * 
	 * @param userInfo
	 */
	private static void makePhoneInfo(UserInfo userInfo) {
		double f = random.nextDouble();
		
		int op = defOP;
		if(defOP == OP_ALL) {
			f = random.nextDouble();
			
			if(f < 0.7109) {
				op = OP_YD;
			} else if (f < 0.9121) {
				op = OP_LT;
			} else /*if (f < 0.8801)*/ {
				op = OP_DX;
			}
		}
		userInfo.op = op;
		makePhoneTyeAndOpName(userInfo, userInfo.op);
		
		if(AutoRunActivity.useImeiDB) {
			int total = ImeiDB.getImeiDB().getImeiTotal();
			if(currentImeiIndex >= total) {
				currentImeiIndex = 0;
			}else {
				currentImeiIndex++;
			}
			userInfo.imei = ImeiDB.getImeiDB().getImeiById(currentImeiIndex);
			
//			Log.e("USERMAKER", "get imeidb = "+userInfo.imei);
		}else {
			userInfo.imei = makeImei();
//			Log.e("USERMAKER", "get = "+userInfo.imei);
		}
		
		userInfo.imsi = makeImsi(op);
		userInfo.simSerial = makeSimSerial(userInfo.imsi);
		userInfo.num = makePhoneNumber(userInfo.op);
	}
	

	/**
	 * 生成手机网络信息（wifi、地域、）
	 * 包括：SSID BSSID
	 * 
	 * @param userInfo
	 */
		
	private static void makeNetworkInfo(UserInfo userInfo) {
		userInfo.mac = makeMAC();
		makeNetworkInfoRandom(userInfo);
	}
	private static void makePhoneTyeAndOpName(UserInfo userInfo, int op) {
		if(op == OP_YD) {
			userInfo.phoneType = TelephonyManager.PHONE_TYPE_GSM;
			userInfo.opName = "中国移动";
		} else if (op == OP_LT) {
			userInfo.phoneType = TelephonyManager.PHONE_TYPE_GSM;
			userInfo.opName = "中国联通";
		} else if (op == OP_DX) {
			userInfo.phoneType = TelephonyManager.PHONE_TYPE_CDMA;
			userInfo.opName = "中国电信";
		}
	}
	private static void makeNetworkInfoRandom(UserInfo userInfo) {
		userInfo.SSID = makeSSID();
		userInfo.BSSID = makeBSSID();

		//2G {"cmwap", "cmnet", "uniwap", "uninet"}
		//3G {"3gwap", "3gnet"}
		//WIFI 30% 2G 50% 3G 18% 4G 1% OTHER 1%
		userInfo.networkType = (Math.random()<0.33? ConnectivityManager.TYPE_WIFI : ConnectivityManager.TYPE_MOBILE);
		
		//如果判定为 wifi 则不需要
		if (userInfo.networkType == ConnectivityManager.TYPE_WIFI) {
			userInfo.netExtra = userInfo.SSID; // wifi is ssid
			//TODO 这个字段的设置会被下面覆盖掉，不知道有什么影响，有待研究
		}
		
		//判定手机SIM卡网络类型及其制式
		int g = 2;
		double f = random.nextDouble();
		
		if (f < 0.59) { // 2G 60%
			g = 2;
			userInfo.netExtra = APNS_2G[random.nextInt(APNS_2G.length)];
			userInfo.simNetworkType = NETWORK_TYPE_2G[random.nextInt(NETWORK_TYPE_2G.length)];
		} else if (f < 0.96) { // 3G 38%
			g = 3;
			userInfo.netExtra = APNS_3G[random.nextInt(APNS_3G.length)];
			userInfo.simNetworkType = NETWORK_TYPE_3G[random.nextInt(NETWORK_TYPE_3G.length)];
		} else if (f < 0.98) { // 4G 2%
			g = 4;
			userInfo.netExtra = APNS_4G[random.nextInt(APNS_4G.length)];
			userInfo.simNetworkType = NETWORK_TYPE_4G[random.nextInt(NETWORK_TYPE_4G.length)];
		} else {
			g = 0;
			userInfo.netExtra = "other";
			userInfo.simNetworkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
		}
		userInfo.g = g;
		
		f = random.nextDouble();
		if(f < 0.96) {
			userInfo.iso = "cn";
		} else {
			userInfo.iso = ISO[random.nextInt(ISO.length)];
		}
	}
	
	private static String makeRandomStr(String str, int len) {
		char[] buf = str.toCharArray();
		for(int i=str.length()-len; i<str.length(); i++) {
			buf[i]=hexs2[random.nextInt(hexs2.length)];
		}
		return new String(buf);
	}
	
	/**
	 * WIFI名称
	 * @return
	 */
	public static String makeSSID() {
		int s = random.nextInt(100);
		if(s < 10) {
			return makeRandomStr("MERCURY_6398D8",6);
		} else if (s < 22) {
			return makeRandomStr("360WiFi-8B45",4);
		} else if (s < 30) {
			return makeRandomStr("ChinaNet-22",2);
		} else if (s < 41) {
			return makeRandomStr("FAST-FE3EC6",6);
		} else if (s < 53) {
			return makeRandomStr("Tenda-039A10",6);
		} else if (s < 64) {
			return makeRandomStr("CMCC-7988",4);
		} else if (s < 88) {
			return makeRandomStr("TP-LINK_E59D4C",6);
		}else {
			return SSIDS[random.nextInt(SSIDS.length)];
		}
	}
	
	public static String makeBSSID() {
		//XX:XX:XX:XX:XX:XX
		char[] mac = new char[17];
		for(int i=0; i<mac.length; i++) {
			if(i%3 == 2)
				mac[i] = ':';
			else
				mac[i] = hexs2[random.nextInt(hexs2.length)];
		}
		String ret = new String(mac);
		
		return ret;
	}
	
	public static String makeMAC() {
		//XX-XX-XX-XX-XX-XX
		char[] mac = new char[17];
		for(int i=0; i<mac.length; i++) {
			if(i%3 == 2)
				mac[i] = ':';
			else
				mac[i] = hexs[random.nextInt(hexs.length)];
		}
		String ret = new String(mac);
		
		log.d(TAG, "new MAC = " + ret);
		
		return ret;
	}
	
	private static boolean isNull(String s) {
		return (s==null || s.length()==0);
	}
	
	public static String makeSimSerial(String imsi) {
		//TODO ICCID
		String sim = "";
		
		char[] c0 = new char[oriUserInfo.simSerial.length()];
		oriUserInfo.simSerial.getChars(0, oriUserInfo.simSerial.length(), c0, 0);
		
		for(int i=1; i<c0.length; i++) {
			c0[i] = (char) ('0' + random.nextInt(10));
		}
		
		sim = new String(c0);
		
		log.d(TAG, "new sim = " + sim);
		
		return sim;
	}
	
	public static String makeImei() {
		//IMEI:"863780023260691"
		//TODO  电信MEID:"A100003FD5F9F5" 14位
		/*
		 * MEID:A000004208B073
		 * 如0xA1000002B0BEB2。开头的0xA表示CDMA手机，如果是0x9, 就表示多模手机。
		 */
		char[] arr = new char[15];
		if(random.nextDouble() < 0.65) {//86开头0.65   
		    arr[0] = '8';
		    arr[1] = '6';
		} else {   //35开头0.35
		    arr[0] = '3';
		    arr[1] = '5';
        }
		for(int i=2; i<arr.length; i++) {
			arr[i] = (char) ('0' + random.nextInt(10));
		}
		/*
		 * 下标6和7 02=32382 06=13780 04=1868 05=1817 01=637 00=307
		 */
		arr[6] = '0';
		int i = random.nextInt(50791);
		arr[7] = i < 32382 ? '2' : i < 46162 ? '6' : i < 48030 ? '4'
				: i < 49847 ? '5' : i < 50484 ? '1' : '0';
		arr[14] = getImeiCheckCode(arr);//校验位
		return new String(arr);
	}
	//获得IMEI校验码
	private static char getImeiCheckCode(char[] arr) {
		int resultInt = 0;
		for (int i = 0; i < 14; i++) {
			int a = Integer.parseInt(String.valueOf(arr[i]));
			i++;
			final int temp = Integer.parseInt(String.valueOf(arr[i])) * 2;
			final int b = temp < 10 ? temp : temp - 9;
			resultInt += a + b;
		}
		resultInt %= 10;
		resultInt = (resultInt == 0) ? 0 : (10 - resultInt);
		return (char) ('0' + resultInt);
	}
	
	public static String makeSid() {
		char[] buf = new char[16];
		
		for(int i=0; i<16; i++) {
			buf[i] = hexs[random.nextInt(16)];
		}
		
		return new String(buf);
	}
	
	public static String makeAid() {
		return makeSid();
	}
	
	//移动：134、135、136、137、138、139、150、151、157(TD)、158、159、187、188 
	//联通：130、131、132、152、155、156、185、186 
	//电信：133、153、180、189、（1349卫通） 
	public static String makePhoneNumber(int op) {
		long num = 0;
		
		int x = 0;
		if(op == OP_ALL) {
			x = random.nextInt(3);
		} else if (op == OP_YD) {
			x = 0;
		} else if (op == OP_LT) {
			x = 1;
		} else if (op == OP_DX) {
			x = 2;
		}
		
		num = 100000000L * nums[x][random.nextInt(nums[x].length)];
		for(int i=7; i>=0; i--) {
			num += random.nextInt(10) * Math.pow(10, i);
		}
		
		String ret = "+86"+String.valueOf(num);
		System.out.println("makePhoneNumber() => " + ret);
		
		return ret;
	}
	/*
 imsi特征
 public static void main(String[] args) {
  String imsi = "460030912121001";
  if("46002,46000,46007".contains(imsi.subSequence(0,5))){
   System.out.println("移动用户");
  }else if("46001,46006".contains(imsi.subSequence(0,5))){
   System.out.println("联通用户");
  }else if("46003,46005".contains(imsi.subSequence(0,5))){
   System.out.println("电信用户");
  }else if("46020".contains(imsi.subSequence(0,5))){
   System.out.println("铁通用户");
  }else{
   System.out.println("非法用户");
  }
 }
	 */
	public static String makeImsi(int op) {
		String imsi = "";
		char[] c0 = new char[15];
		oriUserInfo.imsi.getChars(0, 15, c0, 0);
		
		
		//0 2 7 移动
		//1 联通
		//3 电信
		char[] c1 = {'0', '2', '7', '1', '3'};
		if(op == OP_ALL) {
			c0[4] = c1[random.nextInt(5)];
		} else if (op == OP_YD) {
			c0[4] = c1[random.nextInt(3)];
		} else if (op == OP_LT) {
			c0[4] = '1';
		} else if (op == OP_DX) {
			c0[4] = '3';
		}		
		
		for(int i=0; i<2; i++) {
			c0[5+i] = (char) ('0' + random.nextInt(10));
		}
		for(int i=0; i<4; i++) {
			c0[7+i] = (char) ('0' + random.nextInt(10));
		}
		for(int i=0; i<5; i++) {//改正最后一位不变的现象
			c0[10+i] = (char) ('0' + random.nextInt(10));
		}
		
		imsi = new String(c0);
		
		log.d(TAG, "new imsi = " + imsi);
		
		return imsi;
	}
	
	/**
	 * 从数据库取出来的用户信息需要填充随机信息
	 * 
	 * @param info
	 */
	public static void resetRandom(UserInfo userInfo) {
		makePhoneTyeAndOpName(userInfo, userInfo.op);
		makeNetworkInfoRandom(userInfo);
		makeScreenSize(userInfo);
	}
	
	public static UserInfo initOriginal(Context context) {
		return initWithOriginal(context, oriUserInfo);
	}

	public static UserInfo initWithOriginal(Context context, UserInfo oriUserInfo) {
		//各种可能访问出错
		try {
			WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
			WifiInfo wifiInfo = wm.getConnectionInfo();
			
			oriUserInfo.mac = wifiInfo.getMacAddress();
			oriUserInfo.BSSID = wifiInfo.getBSSID();
			oriUserInfo.SSID = wifiInfo.getSSID();
		} catch (Exception e) {
		}
		
		try {
			ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo info = cm.getActiveNetworkInfo();
			if(info != null) {
				oriUserInfo.netExtra = info.getExtraInfo();
				oriUserInfo.networkType = info.getType();
			}
		} catch (Exception e) {
		}
		
		try {
			TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
			oriUserInfo.opName = tm.getNetworkOperatorName();
			oriUserInfo.iso = tm.getNetworkCountryIso();
			oriUserInfo.phoneType = tm.getPhoneType();
			oriUserInfo.simNetworkType = tm.getNetworkType();
			oriUserInfo.g = 2;
			oriUserInfo.op = OP_YD;
			oriUserInfo.imei = tm.getDeviceId();
			oriUserInfo.imsi = tm.getSubscriberId();
			oriUserInfo.simSerial = tm.getSimSerialNumber();
		} catch (Exception e) {
		}
		
		DisplayMetrics dm = context.getResources().getDisplayMetrics();
		oriUserInfo.screenWidth = dm.widthPixels;
		oriUserInfo.screenHeight = dm.heightPixels;
		oriUserInfo.densityDpi = dm.densityDpi;
		
		oriUserInfo.model = Build.MODEL;
		oriUserInfo.sdk_int = VERSION.SDK_INT;
		oriUserInfo.sdk = VERSION.RELEASE;
		oriUserInfo.board = Build.BOARD;
		oriUserInfo.manufacturer = Build.MANUFACTURER;
		oriUserInfo.device = Build.DEVICE;
		oriUserInfo.brand = Build.BRAND;
		oriUserInfo.hardware = Build.HARDWARE;
		oriUserInfo.fingerprint = Build.FINGERPRINT;
		
		oriUserInfo.aid = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
		oriUserInfo.sid = SystemProperties.get("ro.serialno");
		oriUserInfo.baseband = SystemProperties.get("gsm.version.baseband");
		
		if(isNull(oriUserInfo.imsi))
			oriUserInfo.imsi = "460025958103346";
		if(isNull(oriUserInfo.imei))
			oriUserInfo.imei = "357073059686382";
		if(isNull(oriUserInfo.simSerial))
			oriUserInfo.simSerial = "89860112836032723655";
		if(isNull(oriUserInfo.mac))
			oriUserInfo.mac = "0A:F3:FE:12:23:ED";
		
		return oriUserInfo;
	}
	
	public static UserInfo getOriginalUser() {
		return oriUserInfo;
	}

	public static UserInfo makeNewUser(UserInfo userInfo) {
//		initWithOriginal(context, userInfo);
		makePhoneInfo(userInfo);
		makeNetworkInfo(userInfo);
		makeOthersRandom(userInfo);

		log.i(TAG, "make new user " + userInfo);
		
		return userInfo;
	}
	
	static void setField(Class<?> cls, String name, Object value) {
		try {
			Field field = cls.getDeclaredField(name);
			field.setAccessible(true);
			field.set(null, value);
		} catch (Exception e) {
			System.err.println("UserMaker.setField() set " + value + " fail!");
		}
	}
	
	public static void applayUserInfo(UserInfo userInfo) {
		System.out.print(Build.VERSION.RELEASE);
		System.out.print(Build.MANUFACTURER);
		System.out.print(Build.BRAND);
		System.out.print(Build.BOARD);
		System.out.print(Build.DEVICE);
		System.out.print(Build.DISPLAY);
		System.out.print(Build.HARDWARE);
		System.out.print(Build.SERIAL);
		////////////// 关键匹配数据局
		System.out.print(Build.MODEL); //机型
		System.out.print(Build.FINGERPRINT); //版本号   
		
		
		setField(android.os.Build.VERSION.class, "RELEASE", userInfo.sdk);
		setField(android.os.Build.VERSION.class, "SDK_INT", userInfo.sdk_int);
		setField(android.os.Build.class, "MODEL", userInfo.model);
		setField(android.os.Build.class, "MANUFACTURER", userInfo.manufacturer);
		setField(android.os.Build.class, "BRAND", userInfo.brand);
		setField(android.os.Build.class, "BOARD", userInfo.board);
		setField(android.os.Build.class, "DEVICE", userInfo.device);
		setField(android.os.Build.class, "DISPLAY", userInfo.device);
		setField(android.os.Build.class, "HARDWARE", userInfo.hardware);
		setField(android.os.Build.class, "SERIAL", userInfo.sid);
		setField(android.os.Build.class, "FINGERPRINT", userInfo.fingerprint);
		
		log.i(TAG, "applay user " + userInfo);
	}
}
